/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ccard.core;

import frmwrk.core.AAccountFactory;
import frmwrk.core.Account;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author akefeli
 */
public class AccountFactory implements AAccountFactory {

    @Override
    public Account create(HashMap<String, String> params) {

        Account ret = null;
        int accountNumber = Integer.parseInt("accountNumber");
        Double balance = Double.valueOf(params.get("balance"));
        int ccNumber = Integer.valueOf(params.get("ccNumber"));

        GregorianCalendar expiration = null;
        try {
            DateFormat df = new SimpleDateFormat("dd MM yyyy");
            Date date = df.parse(params.get("expiration"));
            expiration = new GregorianCalendar();
            expiration.setTime(date);
        } catch (ParseException ex) {
            Logger.getLogger(PartyFactory.class.getName()).log(Level.SEVERE, null, ex);
        }

        if (params.get("type").equals("Gold")) {
            
            ret = new Gold(accountNumber, balance, ccNumber, expiration);
            
        } else if (params.get("type").equals("Silver")) {
            
            ret = new Silver(accountNumber, balance, ccNumber, expiration);
            
        } else if (params.get("type").equals("Bronze")) {
            
            ret = new Bronze(accountNumber, balance, ccNumber, expiration);
            
        } else {
            System.out.println("Wrong type for account");
        }

        return ret;
    }
}
